home *** CD-ROM | disk | FTP | other *** search
/ Graphics & Sound Program…ng Techniques for the Mac / Graphics and Sound Programming Techniques for the Mac.iso / M&T Graphics & Sound Examples / Symantec Versions / C02 Sound Playing / P01 Sound Resource / SoundResource.c next >
Encoding:
C/C++ Source or Header  |  1995-08-31  |  2.5 KB  |  103 lines  |  [TEXT/KAHL]

  1. //____________________________________________________________
  2. //
  3. //    SoundResource.c
  4. //
  5. //    Copyright © Dan Parks Sydow, 1995
  6. //    From the book:
  7. //    "Graphics and Sound Programming Techniques for the Mac",
  8. //    M&T Books, 1995
  9. //
  10. //    The "Graphics and Sound Programming for the Mac" book shows the call to SndPlay()
  11. //    with a different second parameter than the one used in this code. The book shows the
  12. //    SndPlay() call as expected by the version of the Sound.h universal header file used
  13. //    by Metrowerks at the time of this writing. Symantec uses a different version of 
  14. //    Sound.h. If Symantec updates the Apple Universal Header files, you may get a compilation 
  15. //    error. If you do, it will concern the call to SndPlay() in the PlaySoundResourceSynch() function.
  16. //    Here is the change you'll need to make. Change
  17. //    FROM:
  18. //
  19. //         theError = SndPlay( theChannel, theHandle, false );
  20. //
  21. //    TO:
  22. //
  23. //         theError = SndPlay( theChannel, (SndListHandle)theHandle, false );
  24.  
  25.  
  26.  
  27. //____________________________________________________________
  28.  
  29. #include <Sound.h>
  30.  
  31.  
  32. //____________________________________________________________
  33.  
  34. void   InitializeToolbox( void );
  35. OSErr  PlaySoundResourceSynch( SndChannelPtr, short );
  36.  
  37.  
  38. //____________________________________________________________
  39.  
  40. #define    rPoliceSiren       9000
  41.  
  42.  
  43. //____________________________________________________________
  44.  
  45. void  main( void )
  46. {
  47.    NumVersion  theSndMgrVers;
  48.    short       theResID;
  49.    OSErr       theError;
  50.    
  51.    InitializeToolbox();
  52.  
  53.    theSndMgrVers = SndSoundManagerVersion();   
  54.    if ( theSndMgrVers.majorRev < 3 )
  55.       ExitToShell();
  56.    
  57.    theResID = rPoliceSiren;
  58.    theError = PlaySoundResourceSynch( nil, theResID );   
  59.    if ( theError != noErr )
  60.       ExitToShell();
  61. }
  62.  
  63.  
  64. //____________________________________________________________
  65.  
  66. OSErr  PlaySoundResourceSynch( SndChannelPtr theChannel, short theResID )
  67. {
  68.    Handle  theHandle;
  69.    OSErr   theError;
  70.    
  71.    theHandle = GetResource( 'snd ', theResID );
  72.    
  73.    if ( theHandle == nil )
  74.    {   
  75.       return ( resProblem );
  76.    }
  77.    else
  78.    {
  79.       HLock( theHandle );
  80.          theError = SndPlay( theChannel, theHandle, false );
  81.       HUnlock( theHandle );
  82.    
  83.       ReleaseResource( theHandle );
  84.  
  85.       return ( theError );
  86.    }
  87. }
  88.  
  89.  
  90. //____________________________________________________________
  91.  
  92. void  InitializeToolbox( void )
  93. {
  94.    InitGraf( &qd.thePort );
  95.    InitFonts();
  96.    InitWindows();
  97.    InitMenus();
  98.    TEInit();
  99.    InitDialogs( 0L );
  100.    FlushEvents( everyEvent, 0 );
  101.    InitCursor();
  102. }
  103.